/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
//import javax.validation.constraints.NotNull;
//import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author The Lunatics
 */
@Entity
@Table(name = "posts")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Posts.findAll", query = "SELECT p FROM Posts p"),
    @NamedQuery(name = "Posts.findByPostId", query = "SELECT p FROM Posts p WHERE p.Post_Id = :postId"),
    @NamedQuery(name = "Posts.findByCircleId", query = "SELECT p FROM Posts p WHERE p.Circle = :circleId"),
    @NamedQuery(name = "Posts.findByUserId", query = "SELECT p FROM Posts p WHERE p.Author = :AuthorId"),
    @NamedQuery(name = "Posts.findByDate", query = "SELECT p FROM Posts p WHERE p.date = :date"),
    @NamedQuery(name = "Posts.findByContent", query = "SELECT p FROM Posts p WHERE p.content = :content"),
    @NamedQuery(name = "Posts.findByCommentCount", query = "SELECT p FROM Posts p WHERE p.commentCount = :commentCount")})
public class Posts implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
//    @NotNull
    @Column(name = "Post_Id")
    private Integer postId;
    @Basic(optional = false)
//    @NotNull
    @Column(name = "Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
//    @Size(max = 50)
    @Column(name = "Content")
    private String content;
    @Column(name = "Comment_Count")
    private Integer commentCount;
    @JoinTable(name = "user_likes_post", joinColumns = {
        @JoinColumn(name = "Post", referencedColumnName = "Post_Id")}, inverseJoinColumns = {
        @JoinColumn(name = "User", referencedColumnName = "User_Id")})
    @ManyToMany
    private Collection<Users> usersCollection;
    @JoinColumn(name = "Circle", referencedColumnName = "Circle_Id")
    @ManyToOne
    private Circles circle;
    @JoinColumn(name = "Author", referencedColumnName = "User_Id")
    @ManyToOne
    private Users author;
    @OneToMany(mappedBy = "post")
    private Collection<Comments> commentsCollection;

    public Posts() {
    }

    public Posts(Integer postId) {
        this.postId = postId;
    }

    public Posts(Integer postId, Date date) {
        this.postId = postId;
        this.date = date;
    }

    public Integer getPostId() {
        return postId;
    }

    public void setPostId(Integer postId) {
        this.postId = postId;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(Integer commentCount) {
        this.commentCount = commentCount;
    }

    @XmlTransient
    public Collection<Users> getUsersCollection() {
        return usersCollection;
    }

    public void setUsersCollection(Collection<Users> usersCollection) {
        this.usersCollection = usersCollection;
    }

    public Circles getCircle() {
        return circle;
    }

    public void setCircle(Circles circle) {
        this.circle = circle;
    }

    public Users getAuthor() {
        return author;
    }

    public void setAuthor(Users author) {
        this.author = author;
    }

    @XmlTransient
    public Collection<Comments> getCommentsCollection() {
        return commentsCollection;
    }

    public void setCommentsCollection(Collection<Comments> commentsCollection) {
        this.commentsCollection = commentsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (postId != null ? postId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Posts)) {
            return false;
        }
        Posts other = (Posts) object;
        if ((this.postId == null && other.postId != null) || (this.postId != null && !this.postId.equals(other.postId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Posts[ postId=" + postId + " ]";
    }
    
}
